package com.qfedu.mtl.service.impl;

import com.qfedu.mtl.dao.MenusDao;
import com.qfedu.mtl.dao.impl.MenusDaoImpl;
import com.qfedu.mtl.entity.Menus;
import com.qfedu.mtl.query.MenusQuery;
import com.qfedu.mtl.service.MenusService;
import com.qfedu.mtl.vo.TableVO;

import java.util.List;

/**
 * @version v1.0
 * @Date 2023/9/28 11:57
 * @Author DARKER
 * @Email 1402216045@qq.com
 */
public class MenusServiceImpl implements MenusService {

    private MenusDao menusDao = new MenusDaoImpl();

    /**
     * 分页并返回前端需要的格式
     * @param page
     * @param size
     * @param menusQuery
     * @return
     */
    @Override
    public TableVO<Menus> findMenusList(Integer page, Integer size, MenusQuery menusQuery) {
        TableVO<Menus> vo = new TableVO<>();
        try {
            List<Menus> menusList = menusDao.selectAll(page, size, menusQuery);
            Integer tolal = menusDao.selectTotal(menusQuery);
            vo.setCode(0);
            vo.setMsg("成功!");
            vo.setCount(tolal);
            vo.setData(menusList);
            return vo;
        }catch (Exception e){
            vo.setCode(-1);
            vo.setMsg("失败!");
            return vo;
        }

    }

    @Override
    public List<Integer> findLevel() {
        return menusDao.selectLevel();
    }

    @Override
    public List<String> findParentMenuCode() {
        return menusDao.selectParentMenuCode();
    }

    @Override
    public void delBatchById(List<Integer> ids) {
        menusDao.delBatchById(ids);
    }
}
